<?php
require_once 'glob.php';
if($_REQUEST['page']==""||$_REQUEST['page']==null)
{
	$page=1;
}else {
	$page=$_REQUEST['page'];
}
if($_REQUEST['classid']==""||$_REQUEST['classid']==null)
{
	$classid=false;
}else {
	$classid=$_REQUEST['classid'];
}
switch ($_REQUEST['action']) {
	case 'list':
		if($classid==false){
		 get_list('sn_info', array( id,name,ordid,isshow),'infolist','info_list.htm','fypage',$page,'where isdel="N" order by ordid','?action=list&');	
			
		}else {
		 get_list('sn_info', array( id,name,ordid,isshow),'infolist','info_list.htm','fypage',$page,'where isdel="N" and classid='.$classid.' order by ordid','?action=list&');	
		}
		
		break;

	case 'add':

		
		//初始化编辑器{$editor1}
		create_html_editor($editor,'fm_content');
		 
		 //获取类别列表
		$xueniao->assign('infoclass',get_clslist('sn_infoclass'));
		 
		//设置默认添加信息的分类
		$xueniao->assign('defaultselectupid',$classid);
		 
		$xueniao->display('info_info.htm');
		
		
		
		break;


	case 'insert':
		if($_REQUEST['fm_name']!=="")
		{
            /*
			if($_REQUEST['fm_downclass']=="" ||$_REQUEST['fm_downclass']==null){
			sys_msg('顶级栏目下不能直接添加信息',1);
			}else{
				*/
			$post=array(
			name=>$_REQUEST['fm_name'],
			isshow=>$_REQUEST['fm_isshow'],
			ordid=>$_REQUEST['fm_ordid'],
			content=>$_REQUEST['fm_content'],
			classid=>$_REQUEST['fm_classid']
			);
			$res=$db->insert('sn_info',$post);
			if($res==true){
				sys_msg('文章添加成功',0);
			
			}
		}else {
			sys_msg('名称不能为空',1);
		}
		break;
	case 'edit':
		if($_REQUEST['id']=="" || $_REQUEST['id']==null)
		{
			sys_msg('未指定信息分类,无法修改', 1);
			exit();
		}else {
			$fm_id=$_REQUEST['id'];
		}

		/******************编辑器内容初始化***********************/

		//初始化编辑器{$editor1}
	 	create_html_editor($editor,'fm_content',getinfo('sn_info','id',$fm_id,'content'));

		
		/******************编辑器内容初始化***********************/


	    //获取类别列表
		$xueniao->assign('infoclass',get_clslist('sn_infoclass'));        
		
	
		get_info('sn_info', 'id,name,ordid,isshow,classid,content', 'info_info', 'info_info.htm','id = '.$fm_id);
		 
		break;
	case 'update':
		if($_REQUEST['id']=="" || $_REQUEST['id']==null)
		{
			sys_msg('未指定信息分类,无法修改', 1);
			exit();
		}else {
			$fm_id=$_REQUEST['id'];
		}
		/*
		if($_REQUEST['fm_downclass']=="" ||$_REQUEST['fm_downclass']==null){
		sys_msg('顶级栏目下不能直接添加信息',1);
		}else{
		*/	
				
				
		$post=array(
		id=>$fm_id,
		//要更改的id
		name=>$_REQUEST['fm_name'],
		isshow=>$_REQUEST['fm_isshow'],
		ordid=>$_REQUEST['fm_ordid'],
		content=>$_REQUEST['fm_content'],
		classid=>$_REQUEST['fm_classid']
		);

		$res=$db->update('sn_info',$post,id);
		if($res==true){
			sys_msg('信息修改成功！',0);
		}else {
		    sys_msg('信息修改失败！',1);
		}


		break;
	default:
		get_list('sn_info', array( id,name,ordid,isshow),'infolist','info_list.htm','fypage',$page,'where isdel="N" and classid='.$classid.' order by ordid','?action=list&');
		break;
}